package ljl.alg.wangzheng_camp.round1.dp;

public class _213_rob {
    
    public int rob(int[] nums) {
        if (nums.length == 1) return nums[0];
        if (nums.length == 2) return Math.max(nums[0], nums[1]);
        return Math.max(doRob(nums, 0, nums.length - 1), doRob(nums, 1, nums.length));
    }
    int doRob(int[] nums, int from, int to) {
        int n1 = nums[from], n2 = Math.max(nums[from + 1], n1);
        for (int i = from + 2; i < to; i++) {
            int t = n2;
            n2 = Math.max(n1 + nums[i], n2);
            n1 = t;
        }
        return n2;
    }
    
}
